package xkp.lesson4;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class TestLambda {
    public static void main(String[] args) {
        MyInterface1 myInterface1 = new MyInterface1() {
            @Override
            public void fun() {
                System.out.println("我是fun()-->匿名内部类");
            }
        };
        myInterface1.fun();

        //此处省略了大括号
        //
        MyInterface1 myInterface11 = ()-> System.out.println("我是fun()-->Lambda表达式");
        myInterface11.fun();

        //(num1,num2)参数列表中数据类型可以省略
        //如果方法体只有一行代码，大阔好可以省略，甚至return也可以省略
        //MyInterface2 myInterface2 = (num1,num2)-> num1+num2;
        MyInterface2 myInterface2 = (num1,num2)-> {return num1+num2;};
        Consumer<String> consumer = t-> System.out.println(t);
        consumer.accept("张三");

        Supplier<Integer> supplier = ()-> 100;
        System.out.println(supplier.get());

        System.out.println("**********************");
        List<String> list = Arrays.asList("张三","李四","王五");
        //遍历list
        //逐个取出列表对象
        //此处发现只是在accept方法中调用了已存在的方法
        //list.forEach(t-> System.out.println(t));
        //::符号为方法引用的标志  对象方法引用
        list.forEach(System.out::println);
        //需求遍历List
        /*for(String str:list){
            System.out.println(str);
        }*/
        //list.forEach(str -> System.out.print(str));
        //list.forEach(System.out::print);

    }
}
